package com.example.springboottest.example.drools;

import org.drools.core.base.RuleNameEndsWithAgendaFilter;
import org.drools.core.base.RuleNameStartsWithAgendaFilter;
import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.builder.KieModule;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;
import org.kie.internal.io.ResourceFactory;

public class RuleFlowTest {
    private static final String drlFile = "/Users/fangdaye/work/workspace/spring-boot-test/src/main/resources/ruleflow/kmodule.xml";

    public static final void main(String[] args) {
        try {
            KieServices ks = KieServices.Factory.get();
            KieContainer kContainer = ks.getKieClasspathContainer();
            KieSession kSession = kContainer.newKieSession("ksession-ruleFlow");

//            StatelessKieSession kStatelessSession = kContainer.newStatelessKieSession("ksession-ruleFlow-stateless");
//            StatelessKieSession kStatelessSession2 = kContainer.newStatelessKieSession("ksession-ruleFlow-stateless");

            PersonFact person = new PersonFact();
            person.setName("张三");
            person.setAge(12);
            person.setSalary(8000);

            kSession.insert(person);

//            kStatelessSession.execute(person);
//            kStatelessSession2.execute(person);

            kSession.startProcess("RuleFlowTest");

            //在规则流的情况下无效
            int count1= kSession.fireAllRules(new RuleNameStartsWithAgendaFilter("test"));  //指定开头的规则执行
            int count2= kSession.fireAllRules(new RuleNameEndsWithAgendaFilter("test"));    //指定结尾的规则执行

            int count3= kSession.fireAllRules();

            kSession.dispose();

//            System.out.println(String.format("drools执行完后，用户姓名：%s", person.getName()));
            System.out.printf("执行完后，用户姓名：%s", person.getName());
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {

        }
    }
}
